home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / os2emxpath.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2008-10-13  |  7.7 KB  |  371 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import os
  5. import stat
  6. __all__ = [
  7.     'normcase',
  8.     'isabs',
  9.     'join',
  10.     'splitdrive',
  11.     'split',
  12.     'splitext',
  13.     'basename',
  14.     'dirname',
  15.     'commonprefix',
  16.     'getsize',
  17.     'getmtime',
  18.     'getatime',
  19.     'getctime',
  20.     'islink',
  21.     'exists',
  22.     'lexists',
  23.     'isdir',
  24.     'isfile',
  25.     'ismount',
  26.     'walk',
  27.     'expanduser',
  28.     'expandvars',
  29.     'normpath',
  30.     'abspath',
  31.     'splitunc',
  32.     'curdir',
  33.     'pardir',
  34.     'sep',
  35.     'pathsep',
  36.     'defpath',
  37.     'altsep',
  38.     'extsep',
  39.     'devnull',
  40.     'realpath',
  41.     'supports_unicode_filenames']
  42. curdir = '.'
  43. pardir = '..'
  44. extsep = '.'
  45. sep = '/'
  46. altsep = '\\'
  47. pathsep = ';'
  48. defpath = '.;C:\\bin'
  49. devnull = 'nul'
  50.  
  51. def normcase(s):
  52.     return s.replace('\\', '/').lower()
  53.  
  54.  
  55. def isabs(s):
  56.     s = splitdrive(s)[1]
  57.     if s != '':
  58.         pass
  59.     return s[:1] in '/\\'
  60.  
  61.  
  62. def join(a, *p):
  63.     path = a
  64.     for b in p:
  65.         if isabs(b):
  66.             path = b
  67.             continue
  68.         if path == '' or path[-1:] in '/\\:':
  69.             path = path + b
  70.             continue
  71.         path = path + '/' + b
  72.     
  73.     return path
  74.  
  75.  
  76. def splitdrive(p):
  77.     if p[1:2] == ':':
  78.         return (p[0:2], p[2:])
  79.     
  80.     return ('', p)
  81.  
  82.  
  83. def splitunc(p):
  84.     if p[1:2] == ':':
  85.         return ('', p)
  86.     
  87.     firstTwo = p[0:2]
  88.     if firstTwo == '//' or firstTwo == '\\\\':
  89.         normp = normcase(p)
  90.         index = normp.find('/', 2)
  91.         if index == -1:
  92.             return ('', p)
  93.         
  94.         index = normp.find('/', index + 1)
  95.         if index == -1:
  96.             index = len(p)
  97.         
  98.         return (p[:index], p[index:])
  99.     
  100.     return ('', p)
  101.  
  102.  
  103. def split(p):
  104.     (d, p) = splitdrive(p)
  105.     i = len(p)
  106.     while i and p[i - 1] not in '/\\':
  107.         i = i - 1
  108.     head = p[:i]
  109.     tail = p[i:]
  110.     head2 = head
  111.     while head2 and head2[-1] in '/\\':
  112.         head2 = head2[:-1]
  113.     if not head2:
  114.         pass
  115.     head = head
  116.     return (d + head, tail)
  117.  
  118.  
  119. def splitext(p):
  120.     (root, ext) = ('', '')
  121.     for c in p:
  122.         if c in ('/', '\\'):
  123.             root = root + ext + c
  124.             ext = ''
  125.             continue
  126.         if c == '.':
  127.             if ext:
  128.                 root = root + ext
  129.                 ext = c
  130.             else:
  131.                 ext = c
  132.         ext
  133.         if ext:
  134.             ext = ext + c
  135.             continue
  136.         root = root + c
  137.     
  138.     return (root, ext)
  139.  
  140.  
  141. def basename(p):
  142.     return split(p)[1]
  143.  
  144.  
  145. def dirname(p):
  146.     return split(p)[0]
  147.  
  148.  
  149. def commonprefix(m):
  150.     if not m:
  151.         return ''
  152.     
  153.     s1 = min(m)
  154.     s2 = max(m)
  155.     n = min(len(s1), len(s2))
  156.     for i in xrange(n):
  157.         if s1[i] != s2[i]:
  158.             return s1[:i]
  159.             continue
  160.     
  161.     return s1[:n]
  162.  
  163.  
  164. def getsize(filename):
  165.     return os.stat(filename).st_size
  166.  
  167.  
  168. def getmtime(filename):
  169.     return os.stat(filename).st_mtime
  170.  
  171.  
  172. def getatime(filename):
  173.     return os.stat(filename).st_atime
  174.  
  175.  
  176. def getctime(filename):
  177.     return os.stat(filename).st_ctime
  178.  
  179.  
  180. def islink(path):
  181.     return False
  182.  
  183.  
  184. def exists(path):
  185.     
  186.     try:
  187.         st = os.stat(path)
  188.     except os.error:
  189.         return False
  190.  
  191.     return True
  192.  
  193. lexists = exists
  194.  
  195. def isdir(path):
  196.     
  197.     try:
  198.         st = os.stat(path)
  199.     except os.error:
  200.         return False
  201.  
  202.     return stat.S_ISDIR(st.st_mode)
  203.  
  204.  
  205. def isfile(path):
  206.     
  207.     try:
  208.         st = os.stat(path)
  209.     except os.error:
  210.         return False
  211.  
  212.     return stat.S_ISREG(st.st_mode)
  213.  
  214.  
  215. def ismount(path):
  216.     (unc, rest) = splitunc(path)
  217.     if unc:
  218.         return rest in ('', '/', '\\')
  219.     
  220.     p = splitdrive(path)[1]
  221.     if len(p) == 1:
  222.         pass
  223.     return p[0] in '/\\'
  224.  
  225.  
  226. def walk(top, func, arg):
  227.     
  228.     try:
  229.         names = os.listdir(top)
  230.     except os.error:
  231.         return None
  232.  
  233.     func(arg, top, names)
  234.     exceptions = ('.', '..')
  235.     for name in names:
  236.         if name not in exceptions:
  237.             name = join(top, name)
  238.             if isdir(name):
  239.                 walk(name, func, arg)
  240.             
  241.         isdir(name)
  242.     
  243.  
  244.  
  245. def expanduser(path):
  246.     if path[:1] != '~':
  247.         return path
  248.     
  249.     i = 1
  250.     n = len(path)
  251.     while i < n and path[i] not in '/\\':
  252.         i = i + 1
  253.     if i == 1:
  254.         if 'HOME' in os.environ:
  255.             userhome = os.environ['HOME']
  256.         elif 'HOMEPATH' not in os.environ:
  257.             return path
  258.         else:
  259.             
  260.             try:
  261.                 drive = os.environ['HOMEDRIVE']
  262.             except KeyError:
  263.                 drive = ''
  264.  
  265.             userhome = join(drive, os.environ['HOMEPATH'])
  266.     else:
  267.         return path
  268.     return userhome + path[i:]
  269.  
  270.  
  271. def expandvars(path):
  272.     if '$' not in path:
  273.         return path
  274.     
  275.     import string
  276.     varchars = string.letters + string.digits + '_-'
  277.     res = ''
  278.     index = 0
  279.     pathlen = len(path)
  280.     while index < pathlen:
  281.         c = path[index]
  282.         if c == "'":
  283.             path = path[index + 1:]
  284.             pathlen = len(path)
  285.             
  286.             try:
  287.                 index = path.index("'")
  288.                 res = res + "'" + path[:index + 1]
  289.             except ValueError:
  290.                 res = res + path
  291.                 index = pathlen - 1
  292.             except:
  293.                 None<EXCEPTION MATCH>ValueError
  294.             
  295.  
  296.         None<EXCEPTION MATCH>ValueError
  297.         if c == '$':
  298.             if path[index + 1:index + 2] == '$':
  299.                 res = res + c
  300.                 index = index + 1
  301.             elif path[index + 1:index + 2] == '{':
  302.                 path = path[index + 2:]
  303.                 pathlen = len(path)
  304.                 
  305.                 try:
  306.                     index = path.index('}')
  307.                     var = path[:index]
  308.                     if var in os.environ:
  309.                         res = res + os.environ[var]
  310.                 except ValueError:
  311.                     res = res + path
  312.                     index = pathlen - 1
  313.                 except:
  314.                     None<EXCEPTION MATCH>ValueError
  315.                 
  316.  
  317.             None<EXCEPTION MATCH>ValueError
  318.             var = ''
  319.             index = index + 1
  320.             c = path[index:index + 1]
  321.             while c != '' and c in varchars:
  322.                 var = var + c
  323.                 index = index + 1
  324.                 c = path[index:index + 1]
  325.             if var in os.environ:
  326.                 res = res + os.environ[var]
  327.             
  328.             if c != '':
  329.                 res = res + c
  330.             
  331.         else:
  332.             res = res + c
  333.         index = index + 1
  334.     return res
  335.  
  336.  
  337. def normpath(path):
  338.     path = path.replace('\\', '/')
  339.     (prefix, path) = splitdrive(path)
  340.     while path[:1] == '/':
  341.         prefix = prefix + '/'
  342.         path = path[1:]
  343.     comps = path.split('/')
  344.     i = 0
  345.     while i < len(comps):
  346.         if comps[i] == '.':
  347.             del comps[i]
  348.             continue
  349.         if comps[i] == '..' and i > 0 and comps[i - 1] not in ('', '..'):
  350.             del comps[i - 1:i + 1]
  351.             i = i - 1
  352.             continue
  353.         if comps[i] == '' and i > 0 and comps[i - 1] != '':
  354.             del comps[i]
  355.             continue
  356.         i = i + 1
  357.     if not prefix and not comps:
  358.         comps.append('.')
  359.     
  360.     return prefix + '/'.join(comps)
  361.  
  362.  
  363. def abspath(path):
  364.     if not isabs(path):
  365.         path = join(os.getcwd(), path)
  366.     
  367.     return normpath(path)
  368.  
  369. realpath = abspath
  370. supports_unicode_filenames = False
  371.